<?php
// +----------------------------------------------------------------------
// | YBlog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.yhustc.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yhustc <yhustc@gmail.com>
// +----------------------------------------------------------------------
// $Id$

/**
 +------------------------------------------------------------------------------
 * YBlog基础模块 加载每个页面都需要显示的内容 定义空操作
 +------------------------------------------------------------------------------
 * @author    yhustc <yhustc@gmail.com>
 * @version   $Id$
 +------------------------------------------------------------------------------
 */

class BaseAction extends Action
{
	/**
     +----------------------------------------------------------
     * 配置选项数组
     +----------------------------------------------------------
     * @var array
     * @access protected
     +----------------------------------------------------------
     */
	private $options;

	 /**
	 +----------------------------------------------------------
	 * 空操作,对于未定义的操作进行报错
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @return void
	 +----------------------------------------------------------
	 */
	function _empty()
	{
		$this->error("请求的页面不存在");
	}
	
	 /**
	 +----------------------------------------------------------
	 * 初始化,加载并缓存用户设置
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @return void
	 +----------------------------------------------------------
	 */
	function _initialize()
	{
		//判断是否有登录,没有登录跳转到登录窗口
		if(!Session::is_set(C('USER_AUTH_KEY')))
		{
			$goto = '';
			if(MODULE_NAME != "Public")
				$goto = base64_encode($_SERVER['REQUEST_URI']);

			$this->redirect("login","Public",'',APP_NAME,array('goto'=>$goto));
		}

		$this->options = S("options");
		if(!$this->options)
		{
			//由于修改了设置,缓存的用户设置信息被清空了
			//重新加载并缓存起来
			$optionDao = D("Options");
			$optionList = $optionDao->where("autoload='yes'")->field("option_name,option_value")->findAll();
			$this->options = $optionDao->getCols($optionList,"option_name,option_value");
			S("options",$this->options);
		}
		$this->assign("options",$this->options);
		
		//判断一下当前操作是不是分类/日志/评论/友链/用户信息等模块的非列表页操作
		//因为没法直接操作前台widget数据缓存文件,所以清空全部前台缓存,最新日志、分类计数、归档等不常变的数据都需要重建缓存
		$clearCacheModule = array("Blog","Comment","Links","Cate_tag","User","Database");
		if(in_array(MODULE_NAME,$clearCacheModule))
			if(ACTION_NAME != "index" && ACTION_NAME != "post")
			//其他几个action全都是除了index都是操作数据的方法,Blog含一个post方法用于显示添加/编辑日志的页面
				clearBlogCache();
		
		//对POST进行安全过滤
		$_POST = inputFilter($_POST);
	}
}
?>